/**
 * @author: wq
 * @Date: 2017/6/26
 * @Time: 16:18
 * <p>
 * Description:
 *          *** 账单API
 */
import axios from 'axios';
import {API_NEW_VERSION} from '../api';
var qs = require('qs');

const INVOICES = API_NEW_VERSION + 'invoices/';
const INVOICE = API_NEW_VERSION + 'invoice/';
const INVOICE_STATUS = API_NEW_VERSION + 'invoice/status';
const INVOICE_IS_ADJUST = API_NEW_VERSION + 'invoice/is_adjust';
const INVOICES_NO_PAGE = API_NEW_VERSION + 'invoices_no_page';

const INVOICES_MEMBER = API_NEW_VERSION + 'invoices/member';

/**
 * 获取对账单列表
 * @param params
 * @returns {AxiosPromise}
 */
export const search = params => {
  return axios.get(INVOICES, {params: params});
};

/**
 * 获取对账单列表根据USERID
 * @param params
 * @returns {AxiosPromise}
 */
export const searchByUserId = params => {
  return axios.get(INVOICES_MEMBER, {params: params});
};

/**
 * 获取对账单列表不分页
 * @param params
 * @returns {AxiosPromise}
 */
export const searchNoPage = params => {
  return axios.get(INVOICES_NO_PAGE, {params: params});
};
/**
 * 保存账单
 * @param params
 * @returns {AxiosPromise}
 */
export const save = params => {
  return axios.post(INVOICES, params);
};

/**
 * 修改账单
 * @param params
 * @returns {AxiosPromise}
 */
export const modify = params => {
  return axios.put(INVOICES, params);
};

/**
 * 获取账单对象
 * @param params
 * @returns {AxiosPromise}
 */
export const retrieve = id => {
  return axios.get(INVOICE + id);
};

/**
 * 删除账单
 * @param id
 * @returns {AxiosPromise}
 */
export const del = id => {
  return axios.delete(INVOICE + id);
};

/**
 * 更改状态
 * @param id
 * @param status
 * @returns {AxiosPromise}
 */
export const invoiceStatus = (id, status) => {
  return axios.post(INVOICE_STATUS, qs.stringify({id: id, status: status}));
};

/**
 * 确认and取消账单调整
 * @param id
 * @param status
 * @returns {AxiosPromise}
 */
export const invoiceIsAdjust = (id, status) => {
  return axios.post(INVOICE_IS_ADJUST, qs.stringify({id: id, status: status}));
};
